package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 部门管理业务层实现类
 */
@Service
@SuppressWarnings("all")
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;


    @Override
    public void deleteDept(Integer id) {
       deptMapper.deleteDept(id);

    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateDept(dept);

    }


    @Override
    public Dept selectId(Integer id) {
        Dept dept=deptMapper.selectId(id);
        return dept;
    }



    @Override
    public PageResult<Dept> page(String name, Integer status, Integer page, Integer pageSize) {
        // 演示使用PageHelper实现分页
        //1 开启分页查询 传统分页使用方式（土）
        PageHelper.startPage(page,pageSize);
        List<Dept> list =deptMapper.list(name,status);
        Page<Dept> rows = (Page<Dept>)list;

        return PageResult.<Dept>builder().total(rows.getTotal()).rows( rows.getResult()).build();
    }


    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }



}
